local anjianl = fk.CreateSkill {
  name = "hanqing__anjianl",
}

Fk:loadTranslationTable{
  ["hanqing__anjianl"] = "暗僭",
  [":hanqing__anjianl"] = "弃牌阶段开始时，你可以<a href='premeditate_href'>“蓄谋”</a>任意次；你使用判定区内的最后一张“蓄谋”牌不可被响应，"..
  "且造成伤害后将手牌摸至体力上限。",

  ["#hanqing__anjianl-put"] = "暗僭：你可以“蓄谋”任意次，将一张手牌作为“蓄谋”牌扣置于判定区",
}

local U = require "packages/utility/utility"

anjianl:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(anjianl.name) and player.phase == Player.Discard and
      not player:isKongcheng() and not table.contains(player.sealedSlots, Player.JudgeSlot)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = anjianl.name,
      cancelable = true,
      prompt = "#hanqing__anjianl-put",
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    U.premeditate(player, event:getCostData(self).cards, anjianl.name)
    while not player:isKongcheng() and not player.dead and not table.contains(player.sealedSlots, Player.JudgeSlot) do
      local cards = room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = anjianl.name,
        cancelable = true,
        prompt = "#hanqing__anjianl-put",
      })
      if #cards > 0 then
        U.premeditate(player, cards, anjianl.name, player)
      else
        return
      end
    end
  end,
})

anjianl:addEffect(fk.PreCardUse, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(anjianl.name) and
      data.extra_data and data.extra_data.premeditate then
      for _, id in ipairs(player:getCardIds("j")) do
        local xumou = player:getVirualEquip(id)
        if xumou and xumou.name == "premeditate" then
          return false
        end
      end
      return true
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = table.simpleClone(player.room.players)
    data.extra_data.hanqing__anjianl = player.id
  end,
})

anjianl:addEffect(fk.Damage, {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(anjianl.name) and data.card and player:getHandcardNum() < player.maxHp then
      local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if use_event then
        local use = use_event.data
        return data.card == use.card and use.extra_data and use.extra_data.hanqing__anjianl == player.id
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(player.maxHp - player:getHandcardNum(), anjianl.name)
  end,
})

return anjianl
